#include <bits/stdc++.h>
using namespace std;

const int maxn = 2005;

int a[maxn],n;

int check(int x) {
    int cnt = 0;
    int nw0 = -1;
    int nw1 = -1;
    for (int i = 0; i < n; i++) {
        if (x & (1 << i)) {
            if (nw1 != -1 && a[nw1] == a[i]) cnt += a[i];
            nw1 = i;
        } else {
            if (nw0 != -1 && a[nw0] == a[i]) cnt += a[i];
            nw0 = i;
        }
    }
    return cnt;
}

int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int ans = 0;
        for (int i = 0; i < (1 << n); i++) {
            ans = max(ans,check(i));
        }
        cout << ans << endl;
    }
    return 0;
}
